package com.gurumades.jsonform.server.forms.dispatch;

import java.util.Map;

import org.codehaus.jackson.JsonNode;

import com.gurumades.jsonform.shared.dispatch.validators.CoreFormItemValidators;
import com.gurumades.jsonform.shared.dispatch.validators.FormItemValidator;

public class CorePreprocessor extends AbstractFormPreprocessor {

	FormItemValidator coreValidators = new CoreFormItemValidators();
	
	public CorePreprocessor() {
		DispatchUtil.registerPreProcessor(new RoleOnlyFilterPreprocessor());
	}
	

	@Override
	public JsonNode preProcessForm(JsonNode form, FormPreprocessHelp helper) {
		helper.addFormItemValidator("*", coreValidators);
		helper.addSubmitHandler(new FormSubmiter() {
			
			@Override
			public void submitForm(String formID, JsonNode form,
					Map<String, JsonNode> values, SubmitHelper submitHelper) {
				System.out.println("The form: "+formID+" Is being submited with values: "+values);
				
			}
		});
		
		return form;
	}

	@Override
	public String[] formIDs() {
		return new String[]{"*"};
	}
}
